/**
 * @param {number} numRows
 * @return {number[][]}
 */
var generate = function(numRows) {
  if(numRows == 1) return [[1]]
  const ans = [[1], [1, 1]]
  for(let i = 2; i < numRows; i++) {
    let temp = [1]
    for(let j = 0; j < ans[i - 1].length - 1; j++) {
      temp.push(ans[i - 1][j] + ans[i - 1][j + 1])
    }
    temp.push(1)
    ans.push(temp)
  }
  return ans
};
console.log(generate(5));